import 'package:flutter/material.dart';
import 'package:flutter_plugin/base/widget/base_stateless_widget.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../res/style.dart';
import '../../../widget/base/cardview.dart';
import '../../../widget/base/row_item_view.dart';
import 'tab_mine_logic.dart';

class TabMinePage extends BaseStatelessWidget<TabMineLogic> {
  TabMinePage({Key? key}) : super(key: key);

  final logic = Get.find<TabMineLogic>();
  final state = Get.find<TabMineLogic>().state;

  @override
  String titleString() {
    return "我的";
  }

  @override
  bool showBackButton() {
    return false;
  }

  @override
  bool setTopBarStyleOrange() {
    return false;
  }

  @override
  Widget buildContent(BuildContext context) {
    return Container(
      width: double.infinity,
      height: double.infinity,
      alignment: Alignment.center,
      decoration: Styles.decorationMain,
      child: ListView(
        children: [
          CardView(
            isRepaint: false,
            margin: EdgeInsets.only(left: 15.w, top: 10.h, right: 15.w, bottom: 10.h),
            padding: EdgeInsets.only(left: 15.w, top: 20.h, right: 15.w, bottom: 20.h),
            radius: 6.r,
            child: GestureDetector(
              onTap: () {
                showToast("点击");
              },
              child: _headView(),
            ),
          ),
          _actionView()
        ],
      ),
    );
  }

  Widget _headView() {
    return Row(
      children: [
        Obx(
          () => ClipRRect(
            borderRadius: BorderRadius.circular(8.r),
            child: state.headImg.value == ""
                ? Image(
                    height: 80.h,
                    width: 80.w,
                    image: const AssetImage('assets/images/ic_header_mine_default.png'),
                  )
                : Image.network(height: 80.h, width: 80.w, state.headImg.value),
          ),
        ),
        Box.wBox10,
        Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(state.name, style: Styles.style_FF333333_16_w500),
            Box.hBox5,
            Text("手机号：${state.phone}", style: Styles.style_FF999999_14_w400),
          ],
        ),
      ],
    );
  }

  Widget _actionView() {
    return Container(
      width: double.infinity,
      height: 227.h,
      margin: EdgeInsets.only(left: 15.w, right: 15.w, bottom: 10.h),
      padding: EdgeInsets.only(left: 15.w, right: 15.w),
      decoration: Styles.decorationWhite,
      child: Column(
        children: [
          RowItemView(
            icon: "assets/images/ic_mine_icon_setting.png",
            name: "更多设置",
            onclick: () {
              showToast("点击更多设置");
            },
          ),
          DividerStyle.lineView(),
          RowItemView(
            icon: "assets/images/ic_mine_icon_about.png",
            name: "关于APP",
            onclick: () {
              showToast("点击关于APP");
            },
          ),
          DividerStyle.lineView(),
          RowItemView(
            icon: "assets/images/ic_mine_icon_update.png",
            name: "升级",
            onclick: () {
              showToast("点击升级");
            },
          ),
          DividerStyle.lineView(),
          RowItemView(
            icon: "assets/images/ic_mine_icon_loginout.png",
            name: "退出登录",
            onclick: () {
              logic.logout();
            },
          ),
        ],
      ),
    );
  }
}
